import random
import unicodedata


def tuple_map(fn, t, **kwargs):
    if t is None:
        return None
    if type(t) not in {list, tuple}:
        return fn(t, **kwargs)
    return tuple(tuple_map(fn, s, **kwargs) for s in t)


def bucket_shuffle(arr, bucket_size: int):
    n = len(arr) // bucket_size
    for i in range(n + 1):
        bucket = arr[i * bucket_size: i * bucket_size + bucket_size]
        random.shuffle(bucket)
        arr[i * bucket_size: i * bucket_size + bucket_size] = bucket


def unicode_to_ascii(s):
    return ''.join(
        c for c in unicodedata.normalize('NFD', s)
        if unicodedata.category(c) != 'Mn'
    )
